home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / 13HLIB.ZIP / PALDEMO.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-28  |  3.6 KB  |  183 lines

  1. /*Paldemo : Palette demonstration.
  2.  
  3.   Creates some nice little effects by fiddling with the palette.
  4.   Please note that it is NOT neccessary to place a WaitVerticalRetrace()
  5.   after every graphics call, as I have done here. The reason for my
  6.   indiscrepancy is that the visual impact is greatly lessened by doing
  7.   things too fast, eg it looks kewl when the 'bars' on the screen
  8.   slowly are fazed in, rather than all appearing instantly as they would
  9.   have if I had removed the WaitVerticalRetrace. In general, use
  10.   WaitVertical Retrace only before several graphics function calls, eg at
  11.   the start of your sprite re-drawing function to reduce flicker.
  12. */
  13.  
  14. #include <conio.h>
  15. #include <dos.h>
  16. #include <stdlib.h>
  17. #include <time.h>
  18. #include "13hlib.h"
  19.  
  20. //Globals
  21. Mode13hLib Mode13h;
  22. ColorStruct ColStr;
  23. int k;
  24. char *a, *b, *c;
  25.  
  26. //Functions
  27. void rotatepalette();
  28. void SetUpPalette();
  29. void SetUpGrayPalette();
  30. void DrawColors();
  31. void DrawGrays();
  32. void ScreenFade();
  33.  
  34. void main()
  35. {
  36.  if(Mode13h.DetectVGA() == FAILURE){
  37.                cprintf("You need a VGA card to run this program.\n\r");
  38.                exit(1);
  39.               }
  40.  Mode13h.SetMode13h();
  41.  a = &ColStr.r;
  42.  b = &ColStr.g;
  43.  c = &ColStr.b;
  44.  SetUpPalette();
  45.  SetUpGrayPalette();
  46.  DrawColors();
  47.  
  48.  for(int j =0; j <= 10; j++)
  49.   {
  50.   delay(20);
  51.   rotatepalette();
  52.   }
  53.  DrawGrays();
  54.  delay(600);
  55.  ScreenFade();
  56.  Mode13h.CloseMode13h();
  57. }
  58.  
  59. void SetUpPalette()
  60. {
  61.  *b = 0;
  62.  *c = 0;
  63.  Mode13h.WaitVerticalRetrace();
  64.  for(k = 1; k<= 63; k += 2)
  65.   {
  66.   *a = k - 1;
  67.   Mode13h.SetPaletteColor(k, ColStr);
  68.   *a = k;
  69.   Mode13h.SetPaletteColor(k + 1, ColStr);
  70.   }
  71.  *a = 0;
  72.  for(k=0; k<=63; k += 2)
  73.   {
  74.    *b = k;
  75.    Mode13h.SetPaletteColor(k + 63, ColStr);
  76.    *b = k + 2;
  77.    Mode13h.SetPaletteColor(k + 64, ColStr);
  78.   }
  79.  *b = 0;
  80.  for(k=0; k<=63; k += 2)
  81.   {
  82.    *c = k;
  83.    Mode13h.SetPaletteColor(k+126, ColStr);
  84.    *c = k +1;
  85.    Mode13h.SetPaletteColor(k+127, ColStr);
  86.   }
  87.  delay(200);
  88. }
  89.  
  90. void SetupGrayPalette()
  91. {
  92.  ColorStruct GreyPal;
  93.  
  94.  
  95.  for(int k = 1; k<= 55; k++)
  96.   {
  97.    GreyPal.r = k;
  98.    GreyPal.g = k;
  99.    GreyPal.b = k;
  100.    Mode13h.SetPaletteColor(k+200, GreyPal);
  101.   }
  102. }
  103.  
  104. void rotatepalette()
  105. {
  106.  a = &ColStr.r;
  107.  b = &ColStr.g;
  108.  c = &ColStr.b;
  109.  delay(15);
  110.  SetUpPalette();
  111.  a = &ColStr.b;
  112.  b = &ColStr.r;
  113.  c = &ColStr.g;
  114.  delay(15);
  115.  SetUpPalette();
  116.  a = &ColStr.g;
  117.  b = &ColStr.b;
  118.  c = &ColStr.r;
  119.  delay(15);
  120.  SetUpPalette();
  121. }
  122.  
  123. void ScreenFade()
  124. {
  125.  for(int j  = 63; j >= 1; j--)
  126.  {
  127.   for(int k = 0; k<= 255; k++)
  128.    {
  129.     Mode13h.GetPaletteColor(k, ColStr);
  130.     if(ColStr.r > 6)
  131.       ColStr.r -= 4;
  132.     else ColStr.r = 0;
  133.     if(ColStr.g > 6)
  134.       ColStr.g -= 4;
  135.     else ColStr.g = 0;
  136.     if(ColStr.b > 6)
  137.       ColStr.b -= 4;
  138.     else ColStr.b = 0;
  139.    Mode13h.SetPaletteColor(k, ColStr);
  140.    }
  141.   Mode13h.WaitVerticalRetrace();
  142.   delay(75);
  143.   }
  144. }
  145.  
  146. void DrawColors()
  147. {
  148.  Mode13h.WaitVerticalRetrace();
  149.  
  150.  for(k=1; k<=189; k++)
  151.  {
  152.   delay(20);           //Slow it down  bit
  153.   Mode13h.HorizontalLine(0, k+3, 319, k);
  154.  }
  155.  
  156.  for(k = 1; k<= 189; k++)
  157.   {
  158.    delay(20);                // Slow it down a bit
  159.    Mode13h.VerticalLine(k + 62, 0, 199, k);
  160.   }
  161.  
  162.  /*
  163.  NOTE: For the above two loops, I included delays so that the columns appear
  164.  slowly.
  165.  If you leave them out, the lines will apeear instantaneously.
  166.  Try it: Comment out one of them and re-compile.
  167.  */
  168. }
  169.  
  170. void DrawGrays()
  171. {
  172.  int height = 200, width = 320;
  173.  
  174.  for(int k = 0; k <= 55; k++)
  175.   {
  176.    delay(50);               // Slow down a bit...
  177.    Mode13h.Rectangle(k, k,  width, height, k+200);
  178.    height-= 2;
  179.    width -= 2;
  180.   }
  181. }
  182.  
  183.